package org.gjy.m8.thread;

import org.junit.Test;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicMarkableReference;
import java.util.concurrent.atomic.DoubleAdder;
import java.util.concurrent.atomic.LongAdder;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-08-26 10:05:16
 */
public class AtomicTest {

    @Test
    public void test3() {
        AtomicMarkableReference<Integer> reference =
                new AtomicMarkableReference<>(0, false);

        boolean b = reference.compareAndSet(0, 1,
                false, true);
        System.out.println("b = " + b);

        System.out.println("reference.getReference() = " + reference.getReference());
    }

    @Test
    public void test2() {
        DoubleAdder adder = new DoubleAdder();
        new AtomicInteger();
    }

    @Test
    public void test1() {
        LongAdder adder = new LongAdder();

        adder.add(1);
        adder.add(1);
        adder.add(1);
        adder.add(1);
        adder.add(1);

        System.out.println(adder.sum());
        System.out.println(adder);
    }
}
